# Maintainer: Andrew Sun <adsun701@gmail.com>

_pyname=PyStemmer
_realname=pystemmer
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}" "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=1.3.0
pkgrel=3
pkgdesc="Snowball stemming algorithms, for information retrieval (mingw-w64)"
arch=('any')
url="http://snowball.tartarus.org"
license=('MIT' 'BSD')
makedepends=("${MINGW_PACKAGE_PREFIX}-python2"
             "${MINGW_PACKAGE_PREFIX}-python3"
             "${MINGW_PACKAGE_PREFIX}-cython2"
             "${MINGW_PACKAGE_PREFIX}-cython"
             "${MINGW_PACKAGE_PREFIX}-python3-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python2-setuptools")
options=('staticlibs' 'strip' '!debug')
source=("${_realname}-${pkgver}.tar.gz"::"http://snowball.tartarus.org/wrappers/${_pyname}-${pkgver}.tar.gz")
sha256sums=('d1ac14eb64978c1697fcfba76e3ac7ebe24357c9428e775390f634648947cb91')

prepare() {  
  cd "${srcdir}"
  # Force cython rebuild
  rm "${_pyname}-${pkgver}/src/Stemmer.c"

  for pver in {2,3}; do
    rm -rf python${pver}-build-${CARCH} | true
    cp -r "${_pyname}-${pkgver}" "python${pver}-build-${CARCH}"
  done
}
  
build() {
  cd "${srcdir}"
  for pver in {2,3}; do
    msg "Python ${pver} build for ${CARCH}"
    cd "${srcdir}/python${pver}-build-${CARCH}"
    ${MINGW_PREFIX}/bin/python${pver} setup.py build
  done
}

package_python3-pystemmer() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3")

  cd "${srcdir}/python3-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build
  
  install -D -m644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python3-${_realname}/LICENSE"
}

package_python2-pystemmer() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2")

  cd "${srcdir}/python2-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build
  
  install -D -m644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python2-${_realname}/LICENSE"
}

package_mingw-w64-i686-python2-pystemmer() {
  package_python2-pystemmer
}

package_mingw-w64-i686-python3-pystemmer() {
  package_python3-pystemmer
}

package_mingw-w64-x86_64-python2-pystemmer() {
  package_python2-pystemmer
}

package_mingw-w64-x86_64-python3-pystemmer() {
  package_python3-pystemmer
}
